﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PrototypeZGame
{
    public abstract class  FuzzySet
    {
        public FuzzySetName name;
        public abstract double getValue(double param);
                
    }

    public class FuzzySetA : FuzzySet
    {
        public double L, M, R;
        public double Al, Bl;
        public double Ar, Br;

        public FuzzySetA(FuzzySetName name,double left, double middle, double right)
        {
            Debug.Assert(left < middle, "left>=middle");
            Debug.Assert(middle < right, "middle>=right");

            this.name = name;
            this.L = left;
            this.M = middle;
            this.R = right;

            Al = 1.0 / (M - L);
            Bl = -L / (M - L);

            Ar = 1.0 / (M - R);
            Br = -R / (M - R);
        }

        public override double getValue(double x)
        {
            if (x <= L)
            {
                return 0;
            }
            else if (x <= M)
            {
                return Al * x + Bl;
            }
            else if (x <= R)
            {
                return Ar * x + Br;
            }
            else
            {
                return 0;
            }
        }
    }

    public class FuzzySetL : FuzzySet
    {
        public double M, R;
        public double Al, Bl;
        public double Ar, Br;

        public FuzzySetL(FuzzySetName name, double middle, double right)
        {
            Debug.Assert(middle < right, "middle>=right");

            this.M = middle;
            this.R = right;
            this.name = name;

            Ar = 1.0 / (M - R);
            Br = -R / (M - R);
        }

        public override double getValue(double x)
        {

            if (x <= M)
            {
                return 1;
            }
            else if (x <= R)
            {
                return Ar * x + Br;
            }
            else
            {
                return 0;
            }
        }
    }


    public class FuzzySetF : FuzzySet
    {
        public double L, M;
        public double Al, Bl;
        public double Ar, Br;

        public FuzzySetF(FuzzySetName name, double left, double middle)
        {
            Debug.Assert(left < middle, "left>=middle");


            this.L = left;
            this.M = middle;
            this.name = name;


            Al = 1.0 / (M - L);
            Bl = -L / (M - L);


        }

        public override double getValue(double x)
        {
            if (x <= L)
            {
                return 0;
            }
            else if (x < M)
            {
                return Al * x + Bl;
            }
            else
            {
                return 1;
            }
        }
    }
}
